package com.le.tester.book.flightjava8.stream;

import cn.hutool.core.util.ReUtil;

import java.util.Random;
import java.util.stream.Collector;
import java.util.stream.IntStream;

/**
 * createTime：2025-08-05 10:52
 * description：prime
 */
public class Prime {
    public boolean isPrime(int candidate) {
//        int candidateRoot = (int) Math.sqrt(candidate);
//        range是开区间
        return IntStream.range(2, candidate)
                .noneMatch(i -> candidate % i == 0);
    }

    public boolean isPrimePlus(int candidate) {

        int candidateRooot = (int) Math.sqrt(candidate);
//        rangClosed是闭区间
        return IntStream.rangeClosed(2, candidateRooot)
                .noneMatch(i -> candidate % i == 0);
    }
}
